<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 
  omit-xml-declaration="yes"
  method="xml"
  encoding="utf-8"
  indent="yes" />
<xsl:param name="modifpizza"/>
<xsl:template match="/pizzas">
	<table id="table_pizzas">
		<xsl:apply-templates select="pizza"/>
	</table>
	<script>
		valider_modif();
	</script>
</xsl:template>
<xsl:template match="pizza">
<xsl:variable name="idpizza" select="@id" />
	<xsl:if test="$modifpizza!=@id">
		<tr>
			<xsl:variable name="image" select="concat('images/pizzas/',@id,'.gif')"/>								
			<th rowspan="2">
				<img src="{$image}"/>
			</th>
			<td rowspan="2" content="nomPizza">
				<xsl:value-of select="nomPizza"/>
			</td>
			<td colspan="2" content="nombase">
				<xsl:variable name="nombase" select="concat('base ',base)"/> 
				<xsl:value-of select="$nombase"/>
			</td>	
			<td rowspan="2" content="prix">
				<xsl:value-of select="prix"/>
			</td>	
			<td rowspan="2" class="bouton-pizza">
				<button idPizza="{$idpizza}" class="button_modif_pizza">
					modifier
				</button>
			</td>		
		</tr>
		<tr class="bas">
			<td  colspan="2" class="trait-tab" content="ingredients" idPizza="{$idpizza}">
				<xsl:for-each select="ingredients/ingredient">
					<xsl:if test="selected='ok'">
						<xsl:variable name="space" select="concat(nom,'  ')"/>
						<xsl:value-of select="$space"/>
					</xsl:if>
				</xsl:for-each>
			</td>			
		</tr>
	</xsl:if>
	<xsl:if test="$modifpizza=@id">
		<tr>
			<xsl:variable name="image" select="concat('images/pizzas/',@id,'.gif')"/>								
			<xsl:variable name="nompizza" select="nomPizza"/>
			<th rowspan="2">
				<img src="{$image}"/>
			</th>
			<td rowspan="2" content="nomPizza">
				<input idpizza="{$idpizza}" type="text" name="nompizza" value="{$nompizza}"/>
			</td>
			<td colspan="2" content="nombase">
				<xsl:variable name="nombase" select="base"/> 
				<input idpizza="{$idpizza}" type="text" name="nombase" value="{$nombase}"/>
			</td>	
			<td rowspan="2" content="prix">
				<xsl:variable name="prix" select="prix"/>
				<input idpizza="{$idpizza}" type="text" name="prix" value="{$prix}"/>
			</td>	
			<td rowspan="2" class="bouton-pizza">
				<button idPizza="{$idpizza}" class="valider">valider</button>
				<button idPizza="{$idpizza}" class="annuler">annuler</button>
			</td>		
		</tr>
		<tr class="bas">
			<td  colspan="2" class="trait-tab" content="ingredients" idPizza="{$idpizza}">
				<select id="modifingredients" name="example" multiple="multiple">
					<xsl:apply-templates select="ingredients/ingredient"/>
				</select>
			</td>			
		</tr>
	</xsl:if>
</xsl:template>
<xsl:template match="ingredient">
	<xsl:variable name="nom" select="nom" />
	<xsl:variable name="id" select="@id"/> 
	<xsl:if test="selected='ok'">
		<option ingredientid="{$id}" value="{$nom}" selected="selected">
			<xsl:value-of select="$nom"/>
		</option>
	</xsl:if>
	<xsl:if test="selected='nok'">
		<option ingredientid="{$id}" value="{$nom}">
			<xsl:value-of select="$nom"/>
		</option>
	</xsl:if>
</xsl:template>
</xsl:stylesheet>